<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<!DOCTYPE html>
<html lang="zh-CN">
  <head>
     
    <title>定时调度程序状态监控</title>
    <link rel="stylesheet" href="bootstrap_3.3.5/css/bootstrap.min.css" type="text/css"></link>
    <script type="text/javascript" src="bootstrap_3.3.5/js/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="bootstrap_3.3.5/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="index.js"></script>
    <style>
     th{
      text-align:center;
      height:34px;
	  line-height:34px !important;
     }
     .table > tbody > tr > td{
       vertical-align:middle;
        text-align:center;
     }
    </style>
 </head>
  
  <body>
   <div style="width:1150px;margin:0 auto;">
    <p style="text-align: center;">
    <br/>       
    <strong><span style="font-size: 20px;">定时调度程序状态监控</span></strong>
    </p>
<p>最后刷新日期：${statisticsDate}</p>
<form  method="post">
    <input name="jobName" type="hidden" />
    <input name="jobGroup" type="hidden" />
    <input name="ruleType" type="hidden" />
    <input name="cronExpression" type="hidden" />
    <input name="cronDescription" type="hidden" />
</form>
<table style="margin:0 auto;" class="table table-hover table-bordered" width="1150">
    <thead>
        <tr>
            <th>序号</th>
            <th>任务分组</th>
            <th>描述</th>
            <th>任务开始时间</th>
            <th>下次执行时间</th>
            <th>下次执行还剩</th>
            <th>状态</th>
            <th colspan="4">
              <div class="btn-group" role="group" aria-label="...">
					  <button type="button" onclick="refreshJob();" class="btn btn-default">刷新</button>
					  <div class="btn-group" role="group">
					    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
					      其他
					      <span class="caret"></span>
					    </button>
					    <ul class="dropdown-menu">
					      <li><a onclick="reSetJob();" href="#">重新载入</a></li>
					      
					    </ul>
					  </div>
					</div>
            </th>
        </tr>
    </thead>
    <tbody>
        <c:forEach items="${jobList}" var="item" varStatus="state">
		        <tr data-jobName="${item.jobName}" data-jobGroup="${item.jobGroup}"> 
		            <td>${state.index+1}</td>
		            <td>${item.jobGroup}</td>
		            <td style="text-align:left"><span class="glyphicon glyphicon-question-sign" title="${item.description}" style="cursor:pointer;margin-right:5px;"></span>${item.jobName}</td>
		            <td>${item.preFrieTime}</td>
		            <td>${item.nextFireTime}</td>
		            <td><div name="during">${item.During }<div></td>
		            <td>${item.state=="NORMAL"?"正常":
		                  item.state=="PAUSED"?"暂停":
		                  item.state=="COMPLETE"?"完成":
		                  item.state=="BLOCKED"?"阻塞":
		                  item.state=="BLOCKED"?"错误":"未知"
		                  }</td>
		        <td><button class="btn btn-default" onclick="submitControl(this,'startJobNow')" >立即开始</button></td>
		        <td><button class="btn btn-default" onclick="submitControl(this,'pauseJob')" ${item.state=="NORMAL" ? "":"disabled=disabled"} >暂停</button></td>
	            <td><button class="btn btn-default" onclick="submitControl(this,'resumeJob')" ${item.state=="PAUSED" ? "":"disabled=disabled"} >恢复</button></td>
	            <td> 
		              <div class="btn-group" role="group">
					    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
					      其他操作
					      <span class="caret"></span>
					    </button>
					    <ul class="dropdown-menu">
					      <li><a onclick="submitControl(this,'moreoneJob')"  href="#">立即执行一次</a></li>
					      <li><a onclick="submitControl(this,'deleteJob')" href="#">删除</a></li>
					      <li role="separator" class="divider"></li>
					      <li><a id="reSetRuleBtn_${state.index+1}" onclick="reSetRuleModelShow(this)" href="#">重新设置调度规则</a></li>
					    </ul>
					  </div>
	             </td>
	             
		        </tr>
	        
        </c:forEach>
         <c:forEach var="i" begin="1" end="${6-fn:length(jobList)}" step="1">
        <tr>
            <td>　</td>
            <td></td>
            <td></td>
           <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        </c:forEach>
        <c:if test="${!empty errorMsg}">
         <div class="alert alert-danger" role="alert">${errorMsg==1?"配置的Cron表达式错误，请重新填写,此次配置无效":""}</div>
        </c:if>
        
        
    </tbody>
</table>
	

<div class="panel panel-default" style="margin-top:20px;">
  <div class="panel-heading">补充说明</div>
  <div class="panel-body">
    <p>基于Quartz RAMJobStore 作业调度，不依赖数据库<br></p>
    <p>1："立即开始"，将暂未开始执行的调度计划立即执行，马上开始调度，若原有计划已开始执行，则放弃以前的时间调度，重新开始调度</p>
    <p>2："立即执行一次"，立即执行一次任务，不影响原有调度计划</p>
    <p>3："删除"，删除整个任务调度，正在执行的任务也会被撤销</p>
    <p>4："重新设置调度规则"，设置后调度立即生效，并且马上开始执行首次任务</p>
    <p>5："刷新"，仅刷新页面，等同于浏览器刷新</p>
    <p>6："重新载入"，仅载入新的任务，可支持热部署，不停机即可自动加载，注意：已被删除的任务也会重新加载</p>
  </div>
</div>

</div>
	<div id="reSetRuleModal" class="modal fade" data-target="">
	  <div class="modal-dialog">
	    <div class="modal-content">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title">重新设置调度规则</h4>
	      </div>
	      <div class="modal-body">
	        <p><label style="width:175px" class="text-right">任务分组：</label><span id="tempGroup"></span> </p>
	        <p><label style="width:175px" class="text-right">任务描述：</label><span id="tempName"></span> </p>
	        <p><label style="width:175px" class="text-right">当前调度规则：</label><span id="tempDescription"></span> </p>
	        <p><label style="width:175px" class="text-right">当前调度Cron:</label><span id="cornText"></span> </p>
	        <div class="form-inline" style="margin-bottom: 5px;">
			  <div class="form-group">
			    <label style="width:175px" class="text-right">调整后的调度规则：</label>
			    <select id="ruleSetOpt" class="form-control" style="width:200px">
	             <option value="1">每分钟执行一次</option>
	             <option value="2">每小时执行一次</option>
	             <option value="3">每天执行一次</option>
	             <option value="0">自定义Corn执行</option>
	           </select>
			  </div>
			</div>
			<div id="cronSet" style="display: none">
	        <div class="form-inline" style="margin-bottom: 5px;">
			  <div class="form-group">
			    <label style="width:175px" class="text-right">调整后Cron表达式：</label>
			    <input type="text" id="cronExpression" style="width:220px" placeholder="" class="form-control">
			  </div>
			</div>
			<div class="form-inline" >
			  <div class="form-group">
			    <label style="width:175px" class="text-right">调整后Cron表达式说明 ：</label>
			    <input type="text" id="cronDescription" style="width:300px" placeholder="" class="form-control">
			  </div>
			</div>
			</div>
	      </div>
	      <div class="modal-footer">
	        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
	        <button type="button" class="btn btn-primary" onclick="reSetRule();">确认</button>
	      </div>
	    </div> 
	  </div> 
	</div> 
  </body>
</html>
